<script type="text/javascript">
var type="";
function listenMessage(msg) {
  show(msg.data,type);
  type="";
}

if (window.addEventListener) {
    window.addEventListener("message", listenMessage, false);
} else {
    window.attachEvent("onmessage", listenMessage);
}
function show(url,type)
{
	if(type=='smallPicture')
	{
		SetFileField(url);
	}
	else
	{
		SetUrl(url);
	}

}
function choose(id)
{
	if(id=='smallPicture')
	{
		type='smallPicture';
	}
	window.open("{$smarty.const.base_popup}","popup",'height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes');
}
function SetUrl(fileUrl)
{
	//document.getElementById( 'cke_114_textInput' ).value = fileUrl;
	var dialog = CKEDITOR.dialog.getCurrent();
		dialog.selectPage('info');
	var tUrl = dialog.getContentElement('info', 'txtUrl');
	tUrl.setValue(fileUrl);
}

// This is a sample function which is called when a file is selected in CKFinder.
function SetFileField(fileUrl )
{
		document.getElementById('smallPicture').innerHTML = "<img src='"+fileUrl+"' width='150px'>";
		document.getElementById('image').value=fileUrl;
}
function SetFileField1(fileUrl )
{
		document.getElementById('smallPicture').innerHTML = "<img src='"+fileUrl+"' width='150px'>";
}
function deletePicture(id)
{
	document.getElementById(id).innerHTML = "<input type='hidden' name='"+id+"' value=''></input>";
}
function delmn(id)
{
	if(confirm("Bạn có chắc chắn muốn xóa Page này?"))
		location.href='{$smarty.const.base_admin}?act=edit-post&do=del&id='+id;
}
function checklink(id){
	if(id.value.substr(0,7)=="http://" || id.value.substr(0,8)=="https://")
		{
		//	id.value=" "+id.value;
		}
}
</script>
<script src="{$smarty.const.base_admin}js/jquery-1.8.2.min.js"></script>
<script>
var $jq183 = jQuery.noConflict();
</script>
<script src="{$smarty.const.base_includes}ckeditor/ckeditor.js"></script>
<link href="{$smarty.const.base_admin}/css/tags.css" rel="stylesheet">
 <script type="text/javascript" src="{$smarty.const.base_admin}/js/script.js"></script>
<script type="text/javascript" src="{$smarty.const.base_admin}/js/tagmanager.js"></script>
<link rel="stylesheet" type="text/css" href="{$smarty.const.base_admin}/css/tagmanager.css" />


 <!-- BEGIN PAGE CONTAINER-->
         <div class="container-fluid">
            <!-- BEGIN PAGE HEADER-->   
            <div class="row-fluid">
               <div class="span12">
                   <!-- BEGIN THEME CUSTOMIZER-->
                   <div id="theme-change" class="hidden-phone">
                       <i class="icon-cogs"></i>
                        <span class="settings">
                            <span class="text">Theme Color:</span>
                            <span class="colors">
                                <span class="color-default" data-style="default"></span>
                                <span class="color-green" data-style="green"></span>
                                <span class="color-gray" data-style="gray"></span>
                                <span class="color-purple" data-style="purple"></span>
                                <span class="color-red" data-style="red"></span>
                            </span>
                        </span>
                   </div>
                   <!-- END THEME CUSTOMIZER-->
                  <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                   <h3 class="page-title">
                     {$nameact}
                   </h3>
                   
                   <!-- END PAGE TITLE & BREADCRUMB-->
               </div>
            </div>
            <!-- END PAGE HEADER-->
            <!-- BEGIN ADVANCED TABLE widget-->
            <div class="row-fluid">
                <div class="span12">
                <!-- BEGIN EXAMPLE TABLE widget-->
                <div class="widget green">
                    <div class="widget-title">
                        <h4><i class="icon-reorder"></i> {$nameact}</h4>
                            <span class="tools">
                                <a href="javascript:;" class="icon-chevron-down"></a>
                                <a href="javascript:;" class="icon-remove"></a>
                            </span>
                    </div>
					{$msg}
                    <div class="widget-body">
                        <form action="" method="post" class="form-horizontal">
				                    <input type=hidden name="id" value='{$data.id}'>
                			<div class="control-group">
                                <label class="control-label">Tiêu đề</label>
                                <div class="controls">
                                    <input type="text" class="span6" name="title" value="{$data.title}" />
                                </div>
                            </div>
							<div class="control-group">
                                <label class="control-label">Chuyên mục</label>
                                <div class="controls">
                                    {$menu}
                                </div>
                            </div>
							<div class="control-group">
                                <label class="control-label">Miêu tả</label>
                                <div class="controls">
                                    <textarea type="text" class="span6" name="described" rows="4">{$data.described}</textarea>
                                </div>
                            </div>
							<div class="control-group">
                                <label class="control-label">Link Trailer</label>
                                <div class="controls">
                                    <input type="text" class="span6" name="trailer" id="trailer" onblur="checklink(this);"; value="{$data.trailer}" />
                                </div>
                            </div>
							<div class="control-group">
                                <label class="control-label">Hiển thị</label>
                                <div class="controls">
                                    <input type="checkbox" name="is_active" value="1" {$data.is_active}></input>
                                </div>
                            </div>
							<div class="control-group">
                                <label class="control-label">Hình ảnh</label>
                                <div class="controls">
                                    <div id="smallPicture">{if $data.image neq ''}<script>SetFileField('{$data.image}');</script>{/if}</div>
									<input type='text' name='image' id="image" value='{$data.image}' onkeyup="SetFileField1(this.value);"></input>
					
									<input type="button" value="Chọn ảnh" onclick="choose('smallPicture');" />
									<input type="button" value="Xóa ảnh" onclick="deletePicture('smallPicture');" />
                                </div>
                            </div>
							<div class="control-group">
                                <label class="control-label">Nội dung</label>
                                <div class="controls">
                                    <textarea class="span12 ckeditor" name="content" rows="6">{$data.content}</textarea>
								</div>
                            </div>
							

							<div class="control-group">
                                    <label class="control-label">Tags</label>
                                    <div class="controls">

									<input type="text" id="tags" autocomplete="off" data-items="6" data-provide="typeahead" name="tags" placeholder="Tags" style="width:9em;" class="input-medium tm-input tm-input-success" data-original-title="">
									<input type="hidden" value="" name="hiddenTagListA">
								
                                    </div>
                                </div>
			  <div class="form-actions">
                      <button type="submit" name="savepost" class="btn blue" value='Lưu bài viết'><i class=" icon-ok"></i> Lưu bài viết</button>
					  <button type="button" class="btn" onclick="delmn({$data.id})"><i class=" icon-remove"></i> Xóa bài viết</button>
                      <button type="button" class="btn" onclick="location.href='{$smarty.const.base_admin}?act=manager-post'"><i class="icon-chevron-left"></i> Trở về</button>
                                </div>
		</form>
                    </div>
                </div>
                <!-- END EXAMPLE TABLE widget-->
                </div>
            </div>

            <!-- END ADVANCED TABLE widget-->
         </div>
         <!-- END PAGE CONTAINER-->
		<script>
  jQuery(document).ready(function () {
    prettyPrint();
  });
  jQuery(".tm-input").typeahead({
                source: function(query, process) {
        var textVal=jQuery(".tm-input").val();
			        jQuery.ajax({
                        url: '{$smarty.const.base_admin}/index.php',
                        type: 'GET',
                        data: { act: "edit-post", ajax: "gettags",code: textVal },
                        dataType: 'JSON',
                        async: true,
                        success: function(data) {
					//	console.log(data);
                            process(data);
            
                        }
                    });
                }
            });
  jQuery(".tm-input").tagsManager({
  prefilled: ["{$data.tags}"],
    typeahead: true,
	typeaheadAjaxPolling: false,
   blinkBGColor_1: '#FFFF9C',
    blinkBGColor_2: '#CDE69C'
  });

</script>